package src.application.Doppelkopf;

import java.net.*;
import java.io.*;

/**
 * Thread fuer Clients
 * @author b.osterholt
 */
public class ClientConnection extends Thread {
    private Socket socket;
    private DataInputStream istream;
    private Client client;
    private String user;
    
    public ClientConnection(Socket s, Client c,String name) {
	socket=s;
	client=c;
	user=name;
    }
    
    /**
     * run-Methode fuer Thread
     */
    @Override
    public void run(){	   
        try{
            byte[] b = new byte[100];
            ByteArrayOutputStream bout = new ByteArrayOutputStream();
            String input; int statusInt;
            boolean status=true;
            
            while(status){
                istream.read(b); 
                bout.write(b);
                input = bout.toString();
                statusInt=client.empfange(input);
		if (statusInt < 0) 
                    status=false; //Empfange schlug fehl -> Beenden
            }
            socket.close();
	} catch(EOFException e) { System.out.println("EOF:"+e.getMessage());
        } catch(IOException e) { System.out.println("IO:"+e.getMessage());
        }
    }
}